package special;

import java.util.*;

class Solution {

    int[] arr;
    Random r = new Random();

    Map<Integer, List<Integer>> map = new HashMap<>();

    public Solution(int[] nums) {
        arr = nums;
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            if (map.containsKey(num)){
                map.get(num).add(i);
            }else {
                List<Integer> list = new ArrayList<>();
                list.add(i);
                map.put(num, list);
            }
        }
    }
    
    public int pick(int target) {
        List<Integer> list = map.get(target);
        int len = list.size();
        int i = r.nextInt(len);
        return list.get(i);
    }
}